package com.cn.admin.controller;


import com.cn.admin.entity.Role;
import com.cn.admin.entity.RoleQuery;
import com.cn.admin.service.RoleService;
import com.cn.admin.vo.ResponseObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/role/list")
    public Object list(){

        List<Role> roles = roleService.selectByExample(new RoleQuery());

        return ResponseObject.success(roles);
    }

    @PostMapping("/role/get")
    public Object get(Long id){

        Role role = roleService.selectByPrimaryKey(id);

        return ResponseObject.success(role);
    }

    @PostMapping("/role/insert")
    public Object get(Role role){

        int i = roleService.insertSelective(role);

        return ResponseObject.success(i);
    }


    @PostMapping("/role/edit")
    public Object edit(Role role){

        int i = roleService.updateByPrimaryKeySelective(role);

        return ResponseObject.success(i);
    }
}
